package com.huike.springboot1.demos.controller;

import com.huike.springboot1.demos.Mapper.UserMapper;
import com.huike.springboot1.demos.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
//控制层
@Controller
public class LoginController {
    @GetMapping("/toLogin")
    public String toLogin(Model model){
//        添加属性，返回currentYear属性数值 
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        return "login";//返回到的页面
    }
    @Autowired
    UserMapper userMapper;
    @PostMapping("/login")
    @ResponseBody
//    如果两端参数名称不同则用@RequestParam注解括起
    public String login(User user) {
        System.out.println(user);
//        使用对象来接受数据
        User user1= userMapper.checkUser(user);
        if(user1==null){
            return "账号密码错误";
        }
        else{
            return "登录成功";
        }
    }
}

